package net.oschina.app.adapter.explore;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import net.oschina.app.R;
import net.oschina.app.base.BaseListAdapter;
import net.oschina.app.bean2.EventBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by 张运湘 on 2017/1/16.
 */

public class MyEventAdapter extends BaseListAdapter<EventBean> {

    @BindView(R.id.tv_end)
    TextView mTvEnd;
    @BindView(R.id.view_line)
    View mViewLine;
    private Context mContext;

    public MyEventAdapter(Context context) {
        mContext = context;
    }

    //提供一个点击接口
    private FriendsRircleAdapter.setItemOnclickListener mItemOnclickListener = null;

    public void setItemOnclickListener(FriendsRircleAdapter.setItemOnclickListener itemOnclickListener) {
        mItemOnclickListener = itemOnclickListener;
    }

    public interface setItemOnclickListener {
        //跳转到详情页面
        Void toDetilactivity();
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_myeventfragment, parent, false);
        RecyclerView.ViewHolder viewHolder = new myEventHolder(view);
        //点击监听
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mItemOnclickListener != null) {
                    mItemOnclickListener.toDetilactivity();
                }
            }
        });
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        EventBean eventBean = mList.get(position);
        ((myEventHolder) holder).mTvMyeventItemDesc.setText(eventBean.getTitle());
        ((myEventHolder) holder).mTvMyeventItemTime.setText(eventBean.getCreateTime());
        ((myEventHolder) holder).mTvMyeventItemContent.setText(eventBean.getSpot());
        if (position==(mList.size()-1)){
            ((myEventHolder) holder).mTvEnd.setVisibility(View.VISIBLE);
            ((myEventHolder) holder).mViewLine.setVisibility(View.VISIBLE);
        }else {
            ((myEventHolder) holder).mTvEnd.setVisibility(View.GONE);
            ((myEventHolder) holder).mViewLine.setVisibility(View.GONE);
        }
    }


    class myEventHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_myevent_state)
        ImageView mIvMyeventState;
        @BindView(R.id.iv_myevent_item)
        ImageView mIvMyeventItem;
        @BindView(R.id.tv_myevent_item_desc)
        TextView mTvMyeventItemDesc;
        @BindView(R.id.tv_myevent_item_time)
        TextView mTvMyeventItemTime;
        @BindView(R.id.tv_myevent_item_content)
        TextView mTvMyeventItemContent;
        @BindView(R.id.tv_end)
        TextView mTvEnd;
        @BindView(R.id.view_line)
        View mViewLine;
        private Context mContext;
        myEventHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
